const AT_CON = r'@magnet:\?xt=urn:btih:[0-9a-fA-F]{40,}?@';
const JIN_CON = r'#\w{12,}?(?:#)';

extension StringCheck on String {
  bool containsCarno() {
    // startsWith(pattern)
    return contains(RegExp(AT_CON)) || contains(RegExp(JIN_CON));
  }

  String carnoByCondition(String con) {
    assert(con.isNotEmpty, '条件不能为空');
    if (!contains(con)) return '';
    int start = 0;
    int end = 0;
    String source = '';
    if (con == '@') {
      source = AT_CON;
    } else {
      source = JIN_CON;
    }
    final matchs = RegExp(source).allMatches(this).toList();
    if (matchs.isEmpty) return '';
    start = matchs.first.start;
    end = matchs.first.end;
    return substring(start, end);
  }

  bool containsSeekId() {
    if (isNotEmpty == true) {
      var itemArr = split("#");
      if (itemArr.length >= 3) {
        for (int i = 1; i < itemArr.length - 1; i++) {
          String subString = itemArr[i];
          if (subString.isNotEmpty && "#$subString#".contains(RegExp(JIN_CON))) {
            return true;
          }
        }
      }
    }
    return false;
  }
}
